package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TestService;
import com.atguigu.tingshu.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author atguigu
 * @ClassName TestController
 * @description: TODO
 * @date 2023年08月22日
 * @version: 1.0
 */
@RestController
@RequestMapping("api/album/test")
public class TestController {

    //  注入服务层方法
    @Autowired
    private TestService testService;

    /**
     * 测试分布式锁
     *
     * @return
     */
    @GetMapping("testLock")
    public Result testLock() {
        testService.testLock();
        return Result.ok();
    }


    /**
     * 写操作 分布式读写锁测试
     *
     * @param id
     * @return
     */
    @GetMapping("/write/{id}")
    public Result write(@PathVariable Long id) {
        testService.write(id);
        return Result.ok();
    }


    /**
     * 写操作 分布式读写锁测试
     *
     * @param id
     * @return
     */
    @GetMapping("/read/{id}")
    public Result read(@PathVariable Long id) {
        id = testService.read(id);
        return Result.ok(id);
    }


    /**
     * 手动扩容布隆过滤器
     *
     * @return 扩容后信息
     */
    @Operation(summary = "手动扩容布隆过滤器")
    @GetMapping("/bloomfilter/resize")
    public Result<Map<String, Object>> bloomfilterResize() {
        Map<String, Object> map = testService.bloomfilterResize();
        return Result.ok(map);
    }


    /***
     * 发送延迟消息
     * @param msg
     * @param ttl
     * @return
     */
    @GetMapping("/sendDelayMsg/{msg}/{ttl}")
    public Result sendDelayMsg(@PathVariable String msg, @PathVariable Long ttl) {
        testService.sendDelayMsg(msg, ttl);
        return Result.ok();
    }
}
